package com.xin.demo.springboot_xin_demo4.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xin.demo.springboot_xin_demo4.pojo.Article;
import com.xin.demo.springboot_xin_demo4.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Calendar;
import java.util.List;

@Controller
public class LoginController {
    @Autowired
    private IArticleService articleService;
    @RequestMapping("/toLoginPage/{page}/{limit}")
    public String toLoginPage(Model model, @PathVariable("page") Integer page, @PathVariable("limit")Integer limit){
        //根据分页查询出所有数据，toLoginPage/{page}/{limit}
        //JSONObject map = new JSONObject();//创建JSONmap来存放JSON数据传到前台
        PageHelper.startPage(page -1, limit);//设置数据库分页查询的范围
        List<Article> articleList = articleService.getArticles(page, limit);//执行service层的方法
        PageInfo<Article> pageInfo=new PageInfo<>(articleList);
        model.addAttribute("count", pageInfo.getTotal());
        model.addAttribute("list", articleList);
        return "index";
    }
}
